package com.va.yahooweather.entity;

import com.va.yahooweather.commons.ConditionUtil;
import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class YCondition implements Serializable{
    private String text = "";
    private int code;
    private int temp;
    private Date date = null;

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getTemp() {
        return temp;
    }

    public void setTemp(int temp) {
        this.temp = temp;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        
        if (this == obj) {
            return true;
        }
        
        YCondition target = (YCondition) obj;
        return new EqualsBuilder()
            .append(getCode(), target.getCode())
            .append(getText(), target.getText())
            .append(getTemp(), target.getTemp())
            .append(getDate().getTime(), target.getDate().getTime())
            .isEquals();
    }

    @Override
    public int hashCode() {
        HashCodeBuilder h = new HashCodeBuilder(5, 51);
        h.append(getCode());
        h.append(getText());
        h.append(getTemp());
        h.append(getDate().getTime());
        return h.hashCode();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        
        sb.append("Current Conditions: \n")
            .append(ConditionUtil.INSTANCE.getDescription(getCode())).append(", ")
            .append(getTemp()).append("\n");
        
        return sb.toString();
    }
    
}
